package org.hishenframework.core.view.interceptor;

import javax.persistence.Entity;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

public class HtmlCreaterInterceptor implements HandlerInterceptor {

	public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
			Object object) throws Exception {
//		System.out.println("11");
		return true;
	}

	public void postHandle(HttpServletRequest request, HttpServletResponse response,
			Object object, ModelAndView mv) throws Exception {
//		mv.setViewName("/common/taglib");
		for (Object o : mv.getModel().values()) {
			Class<?> c = o.getClass();
			if (c.getAnnotation(Entity.class) != null) {
				Model2Html.ModeltoHtml(o);
//				Field[] fields = c.getDeclaredFields();
//				for (Field field : fields) {
//					System.out.println(field.getType());
//				}
			}
		}
	}

	public void afterCompletion(HttpServletRequest request,
			HttpServletResponse response, Object object, Exception exception)
			throws Exception {
//		System.out.println("33");
	}
}
